package io

import (
	"fmt"

	"clean/infra/config"
	"clean/infra/io/driver"
	"clean/usecase"
)

var drivers = make(map[string]io_driver.Driver)

func Register(name string, d io_driver.Driver) {
	drivers[name] = d
}

func Create(cfg config.Config, app usecase.Input) (io_driver.Io, error) {
	d, ok := drivers[cfg.Dialect.Io]
	if !ok {
		return nil, fmt.Errorf("io driver %v not exist", cfg.Dialect.Io)
	}
	return d.Create(cfg, app)
}
